home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / DBMAIN.ASM < prev    next >
Assembly Source File  |  1992-07-07  |  17KB  |  402 lines

  1. ;dbmain.asm
  2. ;Debugger int 1 and main processing module
  3. ;
  4. .386P
  5. ;---------------------------------------------------------------------------- 
  6. ;Copyright 1991, 1992 ASMicro Co. 
  7. ;7/6/91       Rick Knoblaugh
  8. ;-----------------------------------------------------------------------------
  9.                 include dbequ.inc
  10.                 include dbstruc.inc
  11.  
  12. data            segment para public 'data16' use16
  13.                 extrn   save_curs_pos:word, config_attrib:byte, debug_page:byte                        
  14.                 extrn   firstf:byte, wrk_vid_offset:word, io_instrucf:byte
  15.                 extrn   trace_count:word, user_page:byte, get_out:word
  16.                 extrn   edit_routine:word, cmd_buffer:byte, int1_active:byte
  17.                 extrn   io_bpdat:byte, num_io_bp:byte
  18.                 extrn   io_inst_port:word, io_inst_info:byte, tuser_ip:word
  19.                 extrn   tuser_cs:word, video_seg:word
  20.  
  21. data            ends
  22.  
  23. dbstack3        segment para stack 'data16' use16
  24.                 extrn   db_sp3:abs 
  25. dbstack3        ends
  26.  
  27.  
  28. zcode   segment para public 'code16' use16
  29.                 extrn   get_cursor_pos:near, ck_exec_bp:near
  30.                 extrn   get_cursor_pos:near, clear_window:near
  31.                 extrn   set_video_page:near, calc_offset:near, prt_prompt:near
  32.                 extrn   show_regs:near, scroll_cmds_up:near, reset_trap:near
  33.                 extrn   set_trap:near, tmp_disable_all:near          
  34.                 extrn   tmp_disable_io:near, set_video_page:near          
  35.                 extrn   set_cursor_pos:near, reset_tmp_dis:near               
  36.                 extrn   reset_tmp_io:near, editor:near
  37.                 extrn   clear_buffer:near, do_the_cmd:near, skip_white_sp:near
  38.  
  39.                 public  int_1_isr, clear_shift, process_debug   
  40.                 public  xudflag, xud_ip, xud_cs, xud_int, uflags
  41.  
  42.     assume cs:zcode, ds:data, es:nothing
  43.  
  44. uflagshigh      dw      (mask vmbit or mask  resumef) shr 16
  45. uflags          dw      ?
  46. ucs             dw      ?
  47. uip             dw      ?
  48. usp             dw      ?
  49. uss             dw      ?
  50. xudflag         db      FALSE                   ;TRUE if exit to user debugger
  51. xud_int         db      0                       ;int to enter user debug
  52. xud_ip          dw      0                       ;ip of ISR for user debug int
  53. xud_cs          dw      0                       ;cs of ISR for user debug int
  54.  
  55.  
  56.  
  57.  
  58. ;----------------------------------------------------------------------
  59. ;int_1_isr -  Interrupt service routine for int 1                     |
  60. ;                                                                     |
  61. ;----------------------------------------------------------------------
  62. int_1_isr    proc  far 
  63.                 pop     cs:uip          ;get user return address
  64.                 pop     cs:ucs
  65.                 pop     cs:uflags
  66.  
  67.                 mov     cs:usp, sp      ;get user stack
  68.                 mov     sp, ss
  69.                 mov     cs:uss, sp
  70.  
  71.                 mov     sp, dbstack3    ;set up own stack
  72.                 mov     ss, sp
  73.                 mov     sp, db_sp3
  74.  
  75.                 push    cs:uflags       ;put user flags, cs, ip on our stack
  76.                 push    cs:ucs
  77.                 push    cs:uip                                  
  78.  
  79.                 pusha          
  80.  
  81.                 push    ds
  82.                 push    es
  83.                 push    fs
  84.                 push    gs
  85.  
  86.                 push    cs:uss
  87.                 push    cs:usp
  88.                 mov     bp, sp
  89.  
  90.  
  91.                 push    eax
  92.                 push    ebx
  93.                 push    edx
  94.  
  95.  
  96.                 cld
  97.                 mov     ax, DATA
  98.                 mov     ds, ax
  99.  
  100. int_1_050:
  101. ;
  102. ;Check to see if this break point was triggered by debug registers (1-3)
  103. ;with an execution type break point.  If so, we are about to
  104. ;execute that instruction and want to break just after it.  Thus, if this
  105. ;is the case, temporarily disable the break point and set trap flag so
  106. ;break can happen after the instruction completes.  ck_exec_bp does all of
  107. ;this.  It returns with carry set if an execution break point was detected.
  108.  
  109. ;As soon as "P" command is implemented, that logic should be used 
  110. ;in place of this single step method of getting to the next instruction.  The 
  111. ;single step method will be off when stepping across software interrupts (trap
  112. ;flag is cleared).                                 
  113.  
  114. ;ck_exec_bp also checks to see if the user is tracing using another debugger.
  115. ;If this is the case, we will not enter DB.
  116.  
  117.  
  118.                 call    ck_exec_bp              
  119.                 jc      int_1_700               ;if execution break point
  120. int_1_100:
  121.                 call    tmp_disable_io
  122.                 cmp     io_instrucf, TRUE       ;tracing through i/o?
  123.                 jne     short int_1_150
  124.                 cmp     trace_count, 1          ;tracing when I/O happened?
  125.                 jae     short int_1_130         
  126.                 call    reset_trap
  127. int_1_130:
  128.                 call    ck_io_cond              ;see if rest of conditions met
  129.                 jnc     int_1_690               ;exit if not
  130.  
  131. int_1_150:
  132.                 call    tmp_disable_all         ;temporarily disable all bps
  133.  
  134. ;
  135. ;Note:  This version of the debugger makes absolutely no attempt to verify
  136. ;       video mode.  Logic to handle this (e.g. saving graphics etc.
  137. ;       should be added here).
  138. ;
  139.                 call    get_cursor_pos          ;get active page and cursor
  140.                 mov     save_curs_pos, ax
  141.                 mov     user_page, dl
  142.                 mov     ax, video_seg           ;segment for video
  143.                 mov     es, ax
  144.                 mov     ah, config_attrib       ;desired attribute
  145.                 mov     al, ' '                 ;char to use for clear
  146.                 mov     bl, debug_page          ;page for debug display
  147.                 mov     dx, 0000h               ;upper left
  148.                 mov     cx, 184fh               ;lower right
  149.                 cmp     firstf, TRUE            ;first time in debugger?
  150.                 jne     int_1_300
  151.  
  152.                 mov     firstf, FALSE           ;not first time anymore
  153.                 call    clear_window
  154.                 mov     cx, ( (DEBUG_ROW SHL 8) OR DEBUG_COL )
  155.                 call    calc_offset
  156.                 mov     di, ax                  ;video offset in words
  157.                 shl     di, 1
  158.                 mov     wrk_vid_offset, di      ;save prompt location
  159. int_1_300:
  160.                 call    set_video_page
  161.                 mov     di, wrk_vid_offset      ;get prompt location
  162.                 call    prt_prompt              ;print prompt
  163.                 call    show_regs               ;display regs as we enter
  164.                 call    scroll_cmds_up
  165. int_1_400:
  166.                 cmp     trace_count, 1          ;doing trace n?
  167.                 jb      short int_1_500
  168.                 jne     short int_1_450
  169.                 call    reset_trap
  170.                 mov     trace_count, 0
  171.                 jmp     short int_1_500
  172. int_1_450:
  173.                 call    set_trap
  174.                 dec     trace_count
  175.                 mov     ax, [bp].regs_ip 
  176.                 mov     tuser_ip, ax
  177.                 mov     ax, [bp].regs_cs 
  178.                 mov     tuser_cs, ax
  179.                 sti
  180.                 jmp     short int_1_600
  181. int_1_500:
  182. ;
  183. ;Ok now to allow interrupts.  If user has set break points which might
  184. ;occur during interrupts, we will not be interrupted (i.e. debug register
  185. ;type break points and I/O break points are disabled and V86 monitor will
  186. ;not generate int 1 on INT break points when it detects user is in the
  187. ;debugger.
  188. ;
  189.                 sti                              
  190.                 call    process_debug
  191. int_1_600:
  192.                 mov     bl, user_page           ;restore user page
  193.                 call    set_video_page
  194.                 mov     cx, save_curs_pos
  195.                 mov     bl, user_page           ;restore user page                           
  196.                 call    calc_offset
  197.                 call    set_cursor_pos       
  198. int_1_650:
  199.  
  200. ;reset break points which may have been temporarily disabled.
  201.                 cli
  202.                 call    reset_tmp_dis           
  203. int_1_690:
  204.                 call    reset_tmp_io
  205.                 mov     io_instrucf, FALSE      ;clear i/o flag      
  206. int_1_700:
  207.                 mov     int1_active, FALSE      ;out of debugger 
  208.  
  209.                 call    clear_shift
  210.                   
  211.  
  212.                 pop     edx
  213.                 pop     ebx
  214.                 pop     eax
  215.  
  216.  
  217.                 pop     cs:usp
  218.                 pop     cs:uss
  219.                 pop     gs
  220.                 pop     fs
  221.                 pop     es
  222.                 pop     ds
  223.                 popa      
  224.  
  225.                 pop     cs:uip          ;get user return address
  226.                 pop     cs:ucs
  227.                 pop     cs:uflags
  228.                 
  229.                 mov     sp, cs:uss      ;restore user stack
  230.                 mov     ss, cs:uss
  231.                 mov     sp, cs:usp
  232.  
  233.                 cmp     cs:xudflag, TRUE        ;exit to user debugger?
  234.                 je      short int_1_750         ;if so, fix stack and go there 
  235.  
  236.                 push    cs:uflagshigh   ;resume flag set
  237.                 push    cs:uflags       ;user flags
  238.                 push    0
  239.                 push    cs:ucs          ;and return address
  240.                 push    0
  241.                 push    cs:uip
  242.                 iretd                   ;return to application
  243.  
  244. int_1_750:
  245.                 push    cs:uflags       ;user flags
  246.                 push    cs:ucs          ;and return address
  247.                 push    cs:uip
  248.  
  249.                 mov     cs:xudflag, FALSE       ;reset flag
  250. ;
  251. ;Enter user debugger with ints cleared
  252. ;
  253.                 and     cs:uflags, not ( (mask inter) +  (mask trapf)) 
  254.                 push    cs:uflagshigh           ;resume flag set
  255.                 push    cs:uflags               ;user flags
  256.                 push    0
  257.                 push    cs:xud_cs               ;user debugger int cs
  258.                 push    0
  259.                 push    cs:xud_ip               ;user debugger int ip
  260.                 iretd
  261.  
  262. int_1_isr     endp
  263.  
  264.  
  265.  
  266. clear_shift     proc    near
  267.                 push    ds
  268.                 mov     ax, 40h                 ;BIOS data area
  269.                 mov     ds, ax
  270.                 mov     bx, KBD_FLAG                          
  271.                 and     byte ptr [bx], NOT LR_SHIFT
  272.                 pop     ds
  273.                 ret
  274. clear_shift     endp
  275.  
  276.  
  277. ;----------------------------------------------------------------------
  278. ;process_debug - Accept and process user commands.                    |
  279. ;                                                                     |
  280. ;             Enter: es = video segment                               |
  281. ;                    di = offset into video buffer of first           |
  282. ;                         position for user input                     |
  283. ;                    ds = debugger data segment                       |
  284. ;                                                                     |
  285. ;----------------------------------------------------------------------
  286. process_debug   proc    near
  287.                 mov     di, wrk_vid_offset      ;get prompt location
  288.                 call    prt_prompt              ;print prompt
  289.  
  290.                 call    clear_buffer
  291.                 mov     si, offset cmd_buffer
  292. process_d050:      
  293.                 mov     dx, CMD_MAX_LEN         ;max in dl, dh=zero
  294.                 xor     bx, bx                  ;char counter
  295.                 mov     get_out, bx             ;no "get out" key
  296.                 mov     edit_routine, bx        ;no special edit
  297.  
  298. process_d100:       
  299.                 call    editor
  300.  
  301. process_d150:
  302.                 cmp     al, ESC_KEY             ;esc
  303.                 je      short process_d300
  304.  
  305. process_d200:                                   ;ENTER key
  306.  
  307.                 or      dh, dh                  ;any chars entered?
  308.                 jz      short process_debug
  309. process_d250:
  310.  
  311.                 movzx   cx, dh                  ;max chars entered
  312.                 call    skip_white_sp
  313.                 jcxz    process_debug           ;if just spaces entered
  314.  
  315. ;
  316. ;do_the_cmd will return with carry set if cmd processed keeps us in the
  317. ;cmd loop.  Otherwise, we IRET and get control on next int 1.
  318. ;
  319.                 call    do_the_cmd              
  320.                 jc      short process_debug
  321. process_d300:                                   ;ESC key
  322.                 ret
  323. process_debug   endp
  324.  
  325. ;----------------------------------------------------------------------
  326. ;ck_io_cond - Debugger was entered due to an I/O instruction which    | 
  327. ;             accessed one of the ports referenced in a BPIO command. |
  328. ;             Determine if the other conditions specified in the      |
  329. ;             BPIO command(s) have been met.                          |
  330. ;                                                                     |
  331. ;             Note:  currently, the only conditions to check for are  |
  332. ;                    Read or Write.  In the future logic can be added |
  333. ;                    to the BPIO command and this routine to compare  |
  334. ;                    on specific values read or written.  io_inst_info|
  335. ;                    will contain codes indicating type of instruc-   |
  336. ;                    tion ( string, any segment overrides, access     |
  337. ;                    size, etc.).  This could be used to retrieve the |
  338. ;                    value being input or output and make comparisons |
  339. ;                    with user specified conditions.  The structure   |
  340. ;                    used for controlling I/O break points, info_io,  |
  341. ;                    already has the provision for this.              |
  342. ;                                                                     |
  343. ;             If the I/O instruction matches the user specified       |
  344. ;             break point condition, return with carry set else       |
  345. ;             return with carry clear.                                |
  346. ;                                                                     |
  347. ;                                                                     |
  348. ;             Enter: ds = debugger data segment                       |
  349. ;                                                                     |
  350. ;                    io_instrucf = TRUE                               |
  351. ;                                                                     |
  352. ;                   io_inst_port = port address being accessed        |
  353. ;                                                                     |
  354. ;                   io_inst_info = information about the instruction  |
  355. ;                                                                     |
  356. ;              Exit: carry set if condition(s) met                    |
  357. ;                                                                     |
  358. ;                    carry clear if condition(s) not met (debugger    |
  359. ;                    will be exited)                                  |
  360. ;                                                                     |
  361. ;----------------------------------------------------------------------
  362. ck_io_cond      proc    near
  363.                 mov     al, io_inst_info ;info regarding instruction
  364.                 mov     dx, io_inst_port ;port that was accessed
  365.                 sub     ch, ch
  366.                 mov     cl, num_io_bp   ;number of I/O type break points
  367.  
  368.                 mov     bx, offset io_bpdat
  369.                 jmp     short ck_io_200
  370. ck_io_100:
  371.                 add     bx, size info_io  ;advance to next entry
  372. ck_io_200:
  373.                 cmp     [bx].io_stat, AVAIL   ;is this one defined?
  374.                 je      short ck_io_100      ;if not, check next one
  375.                 cmp     dx, [bx].io_port        ;get port address
  376.                 jne     short ck_io_500  
  377.                 push    ax
  378.                 mov     ah, [bx].io_dir                
  379.                 and     ax, ( (INPUT OR OUTPUT) SHL 8) OR \
  380.                                (INPUT OR OUTPUT)  ;isolate direction
  381.                 test    ah, al          ;direction match what user specified?
  382.                 pop     ax
  383.                 jz      short ck_io_500  ;if not
  384. ;
  385. ;Check other conditions here when additional conditions are implemented.
  386. ;
  387.  
  388.                 stc
  389.                 ret
  390. ck_io_500:
  391.                 loop    ck_io_100       ;see if other breakpoints on this I/O
  392.                 clc
  393. ck_io_999:
  394.                 ret
  395. ck_io_cond      endp
  396.  
  397.  
  398.  
  399. zcode           ends
  400.             end          
  401.  
  402.